﻿using System.Collections.Generic;

namespace BlamanticUI.Components.Forms;

/// <summary>
/// Represents a base class for input component in form.
/// </summary>
/// <typeparam name="TValue">The type of the value.</typeparam>
[HtmlTag("input")]
public abstract class BlamanticInputBase<TValue> : BlazorInputComponentBase<TValue>
{
    /// <summary>
    /// Sets to transparent style.
    /// </summary>
    [Parameter] [CssClass("transparent")] public bool Transparent { get; set; }

    protected override string EventName => "oninput";

    /// <summary>
    /// Overrides to set type of input.
    /// </summary>
    protected abstract string Type { get; }

    

    /// <summary>
    /// Build input attributes
    /// </summary>
    /// <param name="attributes">The attributes contains all resolvers to build attributes and <see cref="P:ComponentBuilder.BlazorComponentBase.AdditionalAttributes" />.</param>
    protected override void BuildAttributes(IDictionary<string, object> attributes)
    {
        if (!string.IsNullOrEmpty(Type))
        {
            attributes["type"] = Type;
        }
        attributes["id"] = FieldIdentifier.FieldName;
        attributes["name"] = FieldIdentifier.FieldName;

        AddValueChangedAttribute(attributes);
    }
}
